package com.example.service.usercoupon;

import com.example.dao.usercoupon.UserCouponDao;
import com.example.enums.Status;
import com.example.pojo.BeforeuserAndCoupon;
import com.example.pojo.Usercoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserCouponServiceImp implements  UserCouponService{
    @Autowired
    private UserCouponDao userCouponDao;


    @Override
    public List<Usercoupon> getAll(Usercoupon usercoupon) {

        return userCouponDao.getAll(usercoupon);
    }

    @Override
    public Status UpdateOnline(Integer id, Integer code) {
        boolean b = userCouponDao.UpdateOnline(id, code);
        if (b){
            return Status.OK;
        }else{
            return Status.Error;
        }
    }

    @Override
    public boolean addCoupon(Usercoupon usercoupon) {
        System.out.println((int)(Math.random()*100000));
        usercoupon.setCouponCode((int)(Math.random()*100000));
        return userCouponDao.addCoupon(usercoupon);
    }

    @Override
    public boolean deleteCoupon(Integer id) {
        return userCouponDao.deleteCoupon(id);
    }

    @Override
    public List<BeforeuserAndCoupon> getUserCoupon(String account,String nikename) {
        return userCouponDao.getUserCoupon(account,nikename);
    }

    @Override
    public boolean giveCoupon(List<Usercoupon> coupons) {

        return false;
    }
}
